
#ifndef __tatums_h_
#define __tatums_h_

#define animation_timer_value .5
#define xmlpath "C:/Users/Mayank/Desktop/sun.xml"

#include "ExampleApplication.h"
#include "soundmanager.h"
#include "EchoParser.h"

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif
#include <CEGUI.h>
#include <CEGUISystem.h>
#include <CEGUISchemeManager.h>
#include <OgreCEGUIRenderer.h>
#include <CEGUI/CEGUIImageset.h>
#include <CEGUI/CEGUIWindowManager.h>
#include <CEGUI/CEGUIWindow.h>
#include <CEGUI/CEGUIPropertyHelper.h>



CEGUI::MouseButton convertOISMouseButtonToCegui(int buttonID)
{
    switch (buttonID)
    {
	case 0: return CEGUI::LeftButton;
	case 1: return CEGUI::RightButton;
	case 2:	return CEGUI::MiddleButton;
	case 3: return CEGUI::X1Button;
	default: return CEGUI::LeftButton;
    }
}


class tatumsFrameListener : public ExampleFrameListener, public OIS::KeyListener, public OIS::MouseListener
{
private:
	CEGUI::Renderer* mGUIRenderer;
	bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
public:
	tatumsFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr): ExampleFrameListener(win, cam, true, true)
		 {
        // Populate the camera and scene manager containers
        mCamNode = cam->getParentSceneNode();
        mSceneMgr = sceneMgr;

        // set the rotation and move speed
        mRotate = 0.13;
        mMove = 50;

        // continue rendering
        mContinue = true;

        mMouse->setEventCallback(this);
        mKeyboard->setEventCallback(this);

        mDirection = Vector3::ZERO;

		//strcpy(keyToPress,"awassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsadawassdwdsaawassdwdsasdwaswdawaswdaswadwaswdsawsad");

		timeSinceStart = 0;
		//currentTatumIndex = 0;
		currentBoIndex = 0;
		animationTimer_w = animation_timer_value; //play the w key waiting animation when this value > 0 
		show_w = true; //allowed to show binding box, not allowed to press key
		//when binding box is shown show_w is set to false, and now the player is allowed to press the key.
		animationTimer_a = animation_timer_value;
		show_a = true;
		animationTimer_s = animation_timer_value;
		show_s = true;
		animationTimer_d = animation_timer_value;
		show_d = true;
		playerScore = 0;
		//overlay
		mPlayerOverlay = OverlayManager::getSingleton().getByName("Example/Asg2");
		mPlayerOverlay->show();

		//gameLevel = 1;//.5 is hardest, 4 is easy
		gameLevel = 0; //easy = -3 hard = 3, average = 0
		parsedSong.readXmlFile(xmlpath);
		parsedSong.process();
		bo = parsedSong.getBeatObjects(gameLevel);
		//numTatums = parsedSong.getNumTatums();
		//numTatumsPerBeat = parsedSong.getScalarAttr("numTatumsPerBeat");
		//numSegments = parsedSong.getScalarAttr("numSegments");
		//tatums = parsedSong.getTatums(); //it is pointer to the array of floats
		//segments = parsedSong.getSegments();

		//soundmanager
		mSound = new soundmanager();
		mSound->start();
		mSound->loadsound();
		mSound->play(1);		
    }


	void updateScore(void);
	bool frameStarted(const FrameEvent& evt);
	//bool processUnbufferedKeyInput(const FrameEvent& evt)
	//{
	//	bool ret = ExampleFrameListener::processUnbufferedKeyInput(evt);

	//	// see if switching is on, and you want to toggle
	//	if (mInputTypeSwitchingOn && mKeyboard->isKeyDown(OIS::KC_M) && mTimeUntilNextToggle <= 0)
	//	{
	//		switchMouseMode();
	//		mTimeUntilNextToggle = 1;
	//	}

	//	if (mInputTypeSwitchingOn && mKeyboard->isKeyDown(OIS::KC_K) && mTimeUntilNextToggle <= 0)
	//	{
	//		// must be going from immediate keyboard to buffered keyboard
	//		switchKeyMode();
	//		mTimeUntilNextToggle = 1;
	//	}
	//	return ret;
	//}
 //  void requestShutdown(void)
 //  {
 //     mShutdownRequested = true;
 //  }

	//void switchMouseMode()
	//{
	//	mUseBufferedInputMouse = !mUseBufferedInputMouse;
	//	mMouse->setBuffered(mUseBufferedInputMouse);
	//}
	////-------------------------------------------------------------------------------------
	//void switchKeyMode()
	//{
	//	mUseBufferedInputKeys = !mUseBufferedInputKeys;
	//	mKeyboard->setBuffered(mUseBufferedInputKeys);
	//}

	bool mouseMoved( const OIS::MouseEvent &arg );
	bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
	bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
	bool keyPressed( const OIS::KeyEvent &arg );
	bool keyReleased( const OIS::KeyEvent &arg );
protected:
	Real mRotate;          // The rotate constant
    Real mMove;            // The movement constant

    SceneManager *mSceneMgr;   // The current SceneManager
    SceneNode *mCamNode;   // The SceneNode the camera is currently attached to

    bool mContinue;        // Whether to continue rendering or not
    Vector3 mDirection;     // Value to move in the correct direction

	soundmanager* mSound;

	float timeSinceStart;
	//unsigned int timeSinceStart;
	
	float animationTimer_w,animationTimer_a,animationTimer_s,animationTimer_d;
	bool show_w,show_a,show_s,show_d;
	AnimationState *mAnimationState_w; 
	AnimationState *mAnimationState_a; 
	AnimationState *mAnimationState_s; 
	AnimationState *mAnimationState_d; 
	Overlay* mPlayerOverlay;
	int playerScore;

	//char keyToPress[1000];

	EchoParser parsedSong;
	//int numTatums;
	//float numTatumsPerBeat;
	//float numSegments;
	//float* tatums;
	//vector<Segment*>* segments;
	//int currentTatumIndex;
	int numBo;
	int currentBoIndex;
	vector<BeatObject*>* bo;
	float gameLevel;
};



class tatumsApp : public ExampleApplication
{
   private:
      CEGUI::OgreCEGUIRenderer* mGUIRenderer;
      CEGUI::System* mGUISystem;
	public:
		tatumsApp()
      {}

	~tatumsApp()
	{
      if(mGUISystem)
      {
         delete mGUISystem;
         mGUISystem = 0;
      }
      if(mGUIRenderer)
      {
         delete mGUIRenderer;
         mGUIRenderer = 0;
      }
	}
    void createCamera(void);
    void createScene(void);
    void createFrameListener(void);
};

#endif // #ifndef __tatums_h_